<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>跑马灯效果</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>

<div id="app_1">
    <input type="button" value="开始" @click="startRun">
    <input type="button" value="停止" @click="stopRun">
    <br/>
    <p v-text="msg"></p>
</div>

<script>
    let v = new Vue({
        el: '#app_1',
        data: {
            msg: '小马跑，小马跑，小马快快跑!',
            timer: null
        },
        methods: {
            startRun: function () {
                //console.log("1111");
                if(this.timer != null){return;}
                //console.log("2222");
                this.timer = setInterval(() => {
                    this.msg = this.msg.substring(1) + this.msg.substring(0,1);
                },500);
            },
            stopRun: function () {
                clearInterval(this.timer);
                this.timer = null;
            }
        }
    });
</script>

</body>
</html>